from django.contrib import admin
from django import forms
from pagedown.widgets import AdminPagedownWidget
from models import Category, Article, Visitors, Comments
# Register your models here.


class CategoryAdmin(admin.ModelAdmin):
    list_display = ('title',)
    search_fields = ('title',)
    fieldsets = (
        (
            None,
            {
                'fields': ('title',)
            }
        ),
    )


class ArticleForm(forms.ModelForm):
    class Meta:
        model = Article
        widgets = {
            'content_markdown': AdminPagedownWidget(),
        }
        exclude = ['content_markup', ]


class ArticleAdmin(admin.ModelAdmin):
    form = ArticleForm
    list_display = ('title', 'date_publish')
    search_fields = ('title', 'content_markdown',)
    list_filter = ('categories',)
    fieldsets = (
        (
            None,
            {
                'fields': ('title', 'content_markdown', 'categories')
            }
        ),
    )


admin.site.register(Category, CategoryAdmin)
admin.site.register(Article, ArticleAdmin)
admin.site.register(Visitors)
